<?php
/**
* methodResponse wrapper
* @author J.Ducastel <fredbird@fredbird.org>
* @version
*/
class ooXmlRpcMethodResponse {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access
	* /
	function ooXmlRpcMethodResponse() {
		$this->__construct();
	}/**/

	/**
	*
	* @access
	* /
	function __construct() {

	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* sets content :
	* @param ooxmlrpcparams|ooxmlrpcfault &$content
	* @access public
	* @return bool
	*/
	function setContent(&$content) {
		// check input
		if (!is_a($content,'ooxmlrpcparams') and !is_a($content,'ooxmlrpcfault'))
			return false;
		$this->content=&$content;
		return true;
	}/**/

	/**
	* build and return xml
	* @param
	* @access public
	* @return string
	*/
	function getXml() {
		// get own, root node
		if (!$rootNode=&$this->getNode())
			return false;
		// append content
		if ($this->content)
			$this->content->appendToNode($rootNode);
		// build and return xml
		$doc=$rootNode->getDomDoc();
		return $doc->dump_mem(1);
	}/**/

	/**
	* Return values as an array, if content is set as ooXmlRpcParams
	* @access public
	* @return array
	*/
	function getValues() {
		if (!is_a($this->content,'ooxmlrpcparams'))
			return false;
		return $this->content->getvalues();
	}/**/

	/**
	* Sets from xml string
	* @param string $xml
	* @access public
	* @return bool
	*/
	function setFromXml($xml) {
		// creating domDocument instance
		if (!$domDocument=&domxml_open_mem($xml)) {
			//trigger_error("ooXmlRpcMethodResponse : invalid xml ");
			// echo htmlentities($xml);
			return false;
		}
		// building
		$responseNode=new ooXmlRpcDomNode($domDocument);
		//$deb=&wak::getservice('wakdebug');
		// params or fault ?
		if ($nodes=$responseNode->getXpathNodes('/methodResponse/fault')) {
			// fault
			$this->content=new ooXmlRpcFault();
			$this->content->setFromNode($nodes[0]);
		} else if ($nodes=$responseNode->getxpathNodes('/methodResponse/params')) {
			// params
			$this->content=ooXmlRpcParams();
			//$pNode=&new ooXmlRpcDomNode($nodes[0]);
			$this->content->setFromNode($nodes[0]);
		} else {
			// empty response ???
			return true;
			//return false;
		}
		//$this->params=&new domXmlRpcParams();
		return true;
	}/**/

	/**
	*
	* @param
	* @access public
	* @return
	* /
	function () {

	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var type desc
	*/
	var $content; // ooXmlRpcMethodParams|ooXmlRpcMethodFault

/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* build and return ooXmlRpcNode for content dom manipulation
	* @param
	* @access protected
	* @return ooxmlrpcnode
	*/
	function & getNode() {
		$node=false;
		$baseXml='<?xml version="1.0" encoding="utf-8"?><methodResponse />';
		if (!$dom=&domxml_open_mem($baseXml))
			return $node;
		$doc=&new ooXmlRpcDomNode($dom);
		$roots=&$doc->getxpathnodes('/*');
		$node=$roots[0];

		return $node;
	}/**/

	/**
	*
	* @param
	* @access protected
	* @return
	* /
	function () {

	}/**/
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	*
	* @param
	* @access private
	* @return
	* /
	function () {

	}/**/

	/**
	*
	* @param
	* @access private
	* @return
	* /
	function () {

	}/**/
}
?>
